package hello;

import java.util.*;
import java.math.*;

import org.dom4j.*;
import org.dom4j.io.*;

import org.hibernate.*;
import persistence.*;
import auction.model.*;

public class HelloWorldOneToOne
{
	
	
	public static void main(String[] args)throws Exception
	{
		
		Session s=HibernateUtil.getSessionFactory().openSession();
		Transaction tx=s.beginTransaction();
		
		/*
		UserOneToOnePK userpk=new UserOneToOnePK(new Date().toString());
		AddressOneToOnePK shipAddr=new AddressOneToOnePK("first ring road","610041","cheng du");
		userpk.setShippingAddress(shipAddr);
		shipAddr.setUser(userpk);
		s.save(userpk);
		//s.save(shipAddr);
		*/
		
		/*
		UserOneToOneFK userfk=new UserOneToOneFK(new Date().toString());
		AddressOneToOneFK shipAddr=new AddressOneToOneFK("first ring road","610041","cheng du");
		userfk.setShippingAddress(shipAddr);
		shipAddr.setUser(userfk);
		s.save(userfk);
		*/
		
		UserOneToOneJoin userjoin=new UserOneToOneJoin(new Date().toString());
		AddressOneToOneJoin shipAddr=new AddressOneToOneJoin("first ring road","610041","cheng du");
		userjoin.setShippingAddress(shipAddr);
		//shipAddr.setUser(userfk);
		s.save(userjoin);
		
		tx.commit();
		s.close();
		
		
		/*
		Session s1=HibernateUtil.getSessionFactory().openSession();
		Transaction tx1=s1.beginTransaction();
		AddressOneToOneFK addload=(AddressOneToOneFK)s1.load(AddressOneToOneFK.class,4L);
		out(addload.getUser());
		
		tx1.commit();
		s1.close();
		*/
		
		
		//HibernateUtil.stat();
		HibernateUtil.shutdown();
	}
	
	public static void getParent(Class clazz)
	{
		Class parent=clazz.getSuperclass();
	  if(parent !=null)
	  {
			System.out.println("###"+parent.getName());
			getParent(parent);
		}
	}
	
	static void out(Object obj)
	{
		System.out.println(obj);
	}
}
